<template>

	<view>
		<!--收货地址栏-->
		<my-address></my-address>

		<!--购物车不为空-->
		<view class="cart-container" v-if="cart.length !== 0">
			<!--商品展示栏-->
			<!-- 购物车图标 -->
			<view class="cart-tittle">
				<!-- 左侧图标 -->
				<uni-icons type="shop" size="18"></uni-icons>
				<!--描述文本-->
				<text class="cart-tittle-text">购物车</text>
			</view>
			<!--实现向左滑动删除，需要内外包裹两个标签-->
			<!--滑动删除效果外标签-->
			<uni-swipe-action>
				<!--商品列表-->
				<block v-for="(goods,i) in cart" :key="i">
					<!--滑动删除效果内标签,微信小程序中不能用:options 要用 :right-options-->
					<uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(goods)">
						<my-goods :goods="goods" :showRadio="true" @radio-change="radioClickHandler" :showNum="true"
							@num-change="numChangeHandler"></my-goods>
					</uni-swipe-action-item>
				</block>
			</uni-swipe-action>
		</view>
		<!--购物车为空-->
		<view v-else class="empty-cart">
			<image src="/static/cart_empty@2x.png" class="empty-img"></image>
			<text class="tip-text">空空如也</text>
		</view>

		<!--底部结算区域-->
		<my-settle></my-settle>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';

	export default {
		onLoad() {
			console.log("onLoad...")
			// console.log(this.options)	
		},
		//封装的js组件
		mixins: [badgeMix],
		computed: {
			...mapState('m_cart', ['cart']),
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#C00000'
						// backgroundColor: '#EFEFEF'
					}
				}]
			};
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'removeGoodsById']),
			radioClickHandler(e) {
				console.log("我是cart里面的radio点击事件发生！！！")
				this.updateGoodsState(e)
			},
			numChangeHandler(e) {
				console.log("我是cart里面的numChange点击事件发生！！！")
				console.log(e)
				this.updateGoodsCount(e)
			},
			swipeActionClickHandler(goods) {
				console.log("我是滑动删除操作！！！")
				this.removeGoodsById(goods.goods_id)
			},
		}
	}
</script>

<style lang="scss">
	.cart-tittle {
		height: 40px;
		display: flex;
		align-items: center;
		font-size: 14px;
		padding-left: 5px;
		border-bottom: 1px solid #efefef;

		.cart-tittle-text {
			margin-left: 10px;
		}
	}
	
	.empty-cart{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 150px;
		
		
		.empty-img{
			width: 90px;
			height: 90px;
		}
	}
</style>